home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / gs3.53 / gs_lev2.ps < prev    next >
Text File  |  1996-01-10  |  11KB  |  328 lines

  1. %    Copyright (C) 1990, 1995 Aladdin Enterprises.  All rights reserved.
  2. % This file is part of Aladdin Ghostscript.
  3. % Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  4. % or distributor accepts any responsibility for the consequences of using it,
  5. % or for whether it serves any particular purpose or works at all, unless he
  6. % or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  7. % License (the "License") for full details.
  8. % Every copy of Aladdin Ghostscript must include a copy of the License,
  9. % normally in a plain ASCII text file named PUBLIC.  The License grants you
  10. % the right to copy, modify and redistribute Aladdin Ghostscript, but only
  11. % under certain conditions described in the License.  Among other things, the
  12. % License requires that the copyright notice and this notice be preserved on
  13. % all copies.
  14.  
  15. % Initialization file for Level 2 functions.
  16. % When this is run, systemdict is still writable,
  17. % but (almost) everything defined here goes into level2dict.
  18.  
  19. level2dict begin
  20.  
  21. % ------ Miscellaneous ------ %
  22.  
  23. (<<) cvn /mark load def
  24. (>>) cvn /.dicttomark load def
  25. /currentsystemparams { mark .currentsystemparams .dicttomark } odef
  26. /currentuserparams { mark .currentuserparams .dicttomark } odef
  27. /deviceinfo { currentdevice getdeviceprops .dicttomark readonly } odef
  28. /languagelevel 2 def
  29. % When running in Level 2 mode, this interpreter is supposed to be
  30. % compatible with PostScript version 2010 (I think).
  31. /version (2010) def
  32.  
  33. % If binary tokens are supported by this interpreter,
  34. % set an appropriate default binary object format.
  35. /setobjectformat where
  36.  { pop
  37.    currentsystemparams dup
  38.    /RealFormat get (IEEE) eq { 1 } { 3 } ifelse
  39.    exch /ByteOrder get { 1 add } if
  40.    setobjectformat
  41.  } if
  42.  
  43. % ------ Virtual memory ------ %
  44.  
  45. /currentglobal /currentshared load def
  46. /gcheck /scheck load def
  47. /setglobal /setshared load def
  48. % We can make the global dictionaries very small, because they auto-expand.
  49. /globaldict currentdict /shareddict .knownget not { 4 dict } if def
  50. /GlobalFontDirectory SharedFontDirectory def
  51.  
  52. % ------ IODevices ------ %
  53.  
  54. /.getdevparams where
  55.  { pop /currentdevparams { .getdevparams .dicttomark } odef
  56.  } if
  57. /.putdevparams where
  58.  { pop /setdevparams { mark { } forall counttomark 2 add -1 roll .putdevparams } odef
  59.  } if
  60.  
  61. % ------ Job control ------ %
  62.  
  63. serverdict begin
  64.  
  65. % We could protect the job information better, but we aren't attempting
  66. % (currently) to protect ourselves against maliciousness.
  67.  
  68. /.jobsave null def        % top-level save object
  69. /.jobsavelevel 0 def        % save depth of job (0 if .jobsave is null,
  70.                 % 1 otherwise)
  71. /.adminjob true def        % status of current unencapsulated job
  72.  
  73. /exitserver
  74.  { true exch startjob not { /exitserver /invalidaccess signalerror } if
  75.  } bind def
  76.  
  77. end        % serverdict
  78.  
  79. %**************** The definition of startjob is not complete yet, since
  80. % it doesn't clear the exec stack, doesn't reset stdin/stdout,
  81. % doesn't run the job under its own control, and doesn't reset
  82. % other aspects of the interpreter.
  83. /startjob
  84.  { vmstatus pop pop serverdict /.jobsavelevel get eq
  85.    1 index .checkpassword 0 gt and
  86.     { .checkpassword count 2 roll count 2 sub { pop } repeat
  87.       cleardictstack
  88.       serverdict /.jobsave get dup null eq { pop } { restore } ifelse
  89.       exch
  90.        {    % unencapsulated job
  91.      serverdict /.jobsave null put
  92.      serverdict /.jobsavelevel 0 put
  93.      serverdict /.adminjob 3 -1 roll 1 gt put
  94.        }
  95.        {    % encapsulated job
  96.      serverdict /.jobsave save put
  97.      serverdict /.jobsavelevel 1 put
  98.      userdict /quit /stop load put
  99.      pop
  100.        }
  101.       ifelse true
  102.     }
  103.     { pop pop false
  104.     }
  105.    ifelse
  106.  } odef
  107.  
  108. systemdict begin
  109. /quit
  110.  { //systemdict /serverdict get /.jobsave get null eq
  111.     { //quit }
  112.     { //systemdict /quit get /invalidaccess signalerror }
  113.    ifelse
  114.  } bind odef
  115. end
  116.  
  117. % ------ Compatibility ------ %
  118.  
  119. % In Level 2 mode, the following replace the definitions that gs_statd.ps
  120. % installs in statusdict and serverdict.
  121. % Note that statusdict must be allocated in local VM.
  122. % We don't bother with many of these yet, and the ones defined in terms
  123. % of currentsystemparams are cavalier about allocating a dictionary
  124. % in order to retrieve a single element from it....
  125.  
  126. /.dict1 { exch mark 3 1 roll .dicttomark } bind def
  127.  
  128. currentglobal false setglobal 25 dict exch setglobal begin
  129. currentsystemparams
  130.  
  131. /buildtime 1 index /BuildTime get def
  132. /byteorder 1 index /ByteOrder get def
  133. /checkpassword { .checkpassword 0 gt } bind def
  134. /defaulttimeouts
  135.  { currentsystemparams dup
  136.    /JobTimeout .knownget not { 0 } if
  137.    exch /WaitTimeout .knownget not { 0 } if
  138.    currentpagedevice /ManualFeedTimeout .knownget not { 0 } if
  139.  } bind def
  140. dup /DoStartPage known
  141.  { /dostartpage { currentsystemparams /DoStartPage get } bind def
  142.    /setdostartpage { /DoStartPage .dict1 setsystemparams } bind def
  143.  } if
  144. dup /StartupMode known
  145.  { /dosysstart { currentsystemparams /StartupMode get 0 ne } bind def
  146.    /setdosysstart { { 1 } { 0 } ifelse /StartupMode .dict1 setsystemparams } bind def
  147.  } if
  148. %****** Setting jobname is supposed to set userparams.JobName, too.
  149. /jobname { currentuserparams /JobName get } bind def
  150. /jobtimeout { currentuserparams /JobTimeout get } bind def
  151. %manualfeed
  152. %manualfeedtimeout
  153. /margins
  154.  { currentpagedevice /Margins .knownget { exch } { [0 0] } ifelse
  155.  } bind def
  156. %pagecount
  157. %pagestackorder
  158. /printername
  159.  { currentsystemparams /PrinterName .knownget not { () } if exch copy
  160.  } bind def
  161. %/ramsize { currentsystemparams /RamSize get } bind def
  162. /realformat 1 index /RealFormat get def
  163.  
  164. /.setpagedevice where
  165.  { pop
  166.    /setdefaulttimeouts
  167.     { exch mark /ManualFeedTimeout 3 -1 roll
  168.       /Policies mark /ManualFeedTimeout 1 .dicttomark
  169.       .dicttomark setpagedevice
  170.       /WaitTimeout exch mark /JobTimeout 5 2 roll .dicttomark setsystemparams
  171.     } bind def
  172.    /setmargins
  173.     { exch 2 array astore /Margins .dict1 setpagedevice
  174.     } bind def
  175.  }
  176. if
  177. %setpagestackorder
  178. dup /PrinterName known
  179.  { /setprintername { /PrinterName .dict1 setsystemparams } bind def
  180.  } if
  181. currentuserparams /WaitTimeout known
  182.  { /waittimeout { currentuserparams /WaitTimeout get } bind def
  183.  } if
  184.  
  185. /.setpagedevice where
  186.  { pop 
  187.    /pagemargin
  188.     { currentpagedevice /PageOffset .knownget { 0 get } { 0 } ifelse
  189.     } bind def
  190.    /pageparams
  191.     { currentpagedevice
  192.       dup /Orientation .knownget { 1 and ORIENT1 { 1 xor } if } { 0 } ifelse exch
  193.       dup /PageSize get aload pop 3 index 0 ne { exch } if 3 2 roll
  194.       /PageOffset .knownget { 0 get } { 0 } ifelse 4 -1 roll
  195.     } bind def
  196.    /.setpagesize { 2 array astore /PageSize .dict1 setpagedevice } bind def
  197.    /setduplexmode { /Duplex .dict1 setpagedevice } bind def
  198.    /setpagemargin { 0 2 array astore /PageOffset .dict1 setpagedevice } bind def
  199.    /setpageparams
  200.     { mark /PageSize 6 -2 roll
  201.       4 index 1 and ORIENT1 { 1 } { 0 } ifelse ne { exch } if 2 array astore
  202.       /Orientation 5 -1 roll ORIENT1 { 1 xor } if
  203.       /PageOffset counttomark 2 add -1 roll 0 2 array astore
  204.       .dicttomark setpagedevice
  205.     } bind def
  206.    /setresolution
  207.     { dup 2 array astore /HWResolution .dict1 setpagedevice
  208.     } bind def
  209.  }
  210. if
  211.  
  212. pop        % currentsystemparams
  213.  
  214. % Flag the current dictionary so it will be swapped when we
  215. % change language levels.  (See zmisc2.c for more information.)
  216. /statusdict currentdict def
  217.  
  218. currentdict end
  219. /statusdict exch def
  220.  
  221. % ------ Color spaces ------ %
  222.  
  223. % Define the setcolorspace procedures.
  224. /colorspacedict mark
  225.   /DeviceGray { pop 0 setgray } bind
  226.   /DeviceRGB { pop 0 0 0 setrgbcolor } bind
  227.   /setcmykcolor where
  228.    { pop /DeviceCMYK { pop 0 0 0 1 setcmykcolor } bind
  229.    } if
  230.   /.setcieaspace where
  231.    { pop /CIEBasedA { NOCIE { pop 0 setgray } { 1 get .setcieaspace } ifelse } bind
  232.    } if
  233.   /.setcieabcspace where
  234.    { pop /CIEBasedABC { NOCIE { pop 0 0 0 setrgbcolor } { 1 get .setcieabcspace } ifelse } bind
  235.    } if
  236.   /.setciedefspace where
  237.    { pop /CIEBasedDEF { NOCIE { pop 0 0 0 setrgbcolor } { 1 get .setciedefspace } ifelse } bind
  238.    } if
  239.   /.setciedefgspace where
  240.    { pop /CIEBasedDEFG { NOCIE { pop 0 0 0 1 setcmykcolor } { 1 get .setciedefgspace } ifelse } bind
  241.    } if
  242.   /.setseparationspace where
  243.    { pop /Separation { dup 2 get setcolorspace .setseparationspace } bind
  244.    } if
  245.   /.setindexedspace where
  246.    { pop /Indexed { dup 1 get setcolorspace .setindexedspace } bind
  247.    } if
  248.   /.setpatternspace where
  249.    { pop /Pattern
  250.       { dup length 1 gt { dup 1 get setcolorspace } if
  251.         .setpatternspace
  252.       } bind
  253.    } if
  254. .dicttomark def
  255.  
  256. /.devcs [/DeviceGray /DeviceRGB /DeviceCMYK] readonly def
  257. /currentcolorspace
  258.  { .currentcolorspace dup type /integertype eq
  259.     { //.devcs exch 1 getinterval
  260.     } if
  261.  } odef
  262. currentdict /.devcs undef
  263.  
  264. /setcolorspace
  265.  { dup type /nametype eq { 1 array astore } if
  266.    dup //colorspacedict 1 index 0 get get exec
  267.    .setcolorspace
  268.  } odef
  269.  
  270. % Initialize the CIE rendering dictionary if necessary.
  271. % The most common CIE files seem to assume the "calibrated RGB color space"
  272. % described on p. 189 of the PostScript Language Reference Manual,
  273. % 2nd Edition; we simply invert this transformation back to RGB.
  274. /setcolorrendering where
  275.  { pop mark
  276.    /ColorRenderingType 1
  277. % We must make RangePQR and RangeLMN large enough so that values computed by
  278. % the assumed encoding MatrixLMN don't get clamped.
  279.    /RangePQR [0 0.9505 0 1 0 1.0890]
  280.    /TransformPQR [ { 4 { exch pop } repeat } dup dup ]
  281.    /RangeLMN [0 0.9505 0 1 0 1.0890]
  282.    /MatrixABC
  283.     [ 3.24063 -0.96893  0.05571
  284.      -1.53721  1.87576 -0.20402
  285.      -0.49863  0.04152  1.05700
  286.     ]
  287.    /EncodeABC [{0 max 0.45 exp} bind dup dup]
  288.    /WhitePoint [0.9505 1 1.0890]
  289.    .dicttomark setcolorrendering
  290.  } if
  291.  
  292. % ------ Painting ------ %
  293.  
  294. % A straightforward definition of execform that doesn't actually
  295. % do any caching.
  296. /execform
  297.  { dup /Implementation known not
  298.     { dup /FormType get 1 ne { /rangecheck signalerror } if
  299.       dup /Implementation null put readonly
  300.     } if
  301.    gsave dup /Matrix get concat
  302.    dup /BBox get aload pop
  303.    exch 3 index sub exch 2 index sub rectclip
  304.    dup /PaintProc get exec
  305.    grestore
  306.  } odef
  307.  
  308. /makepattern
  309.  { currentglobal
  310.     { false setglobal .buildpattern true setglobal }
  311.     { .buildpattern }
  312.    ifelse
  313.    exch dup length 1 add dict copy
  314.    dup /Implementation 4 -1 roll put
  315.    readonly
  316.  } odef
  317.  
  318. /setpattern
  319.  { currentcolorspace 0 get /Pattern ne
  320.     { [ /Pattern currentcolorspace ] setcolorspace } if
  321.    setcolor
  322.  } odef
  323.  
  324. end                % level2dict
  325.